package com.friendsoft.web.bean;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.friendsoft.crm.bean.UserBean;
import com.friendsoft.crm.entity.Contact;
import com.friendsoft.crm.entity.User;


@SessionScoped
@ManagedBean
public class RegistrationBean {
	@EJB
	private UserBean userBean;

	private User user;
	private String userName;
	private String password;
	private String firstName;
	private String lastName;
	private String email;
	private String welcomeMessage;

	/**
	 * @return the userBean
	 */
	public UserBean getUserBean() {
		return userBean;
	}

	/**
	 * @param userBean the userBean to set
	 */
	public void setUserBean(UserBean userBean) {
		this.userBean = userBean;
	}

	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * @param userName the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return the welcomeMessage
	 */
	public String getWelcomeMessage() {
		return welcomeMessage;
	}

	/**
	 * @param welcomeMessage the welcomeMessage to set
	 */
	public void setWelcomeMessage(String welcomeMessage) {
		this.welcomeMessage = welcomeMessage;
	}

	public void makeWelcomeMessage() {
		welcomeMessage = "Welcome " + firstName + " " + lastName + " to the page";
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @param user the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}

	public String createUser() {
		User newUser = new User();
		newUser.setUsername(userName);
		newUser.setPassword(password);
		Contact newContact = new Contact();
		newContact.setFirstName(firstName);
		newContact.setLastName(lastName);
		List<Contact> contacts = new ArrayList<Contact>();
		contacts.add(newContact);
		newUser.setContacts(contacts);
		userBean.createUser(newUser);
		return null;
	}
}
